
package com.eling.elcms.travel.service.impl;

import com.eling.elcms.basedoc.model.*;
import com.eling.elcms.basedoc.model.ContactAddress.AddressStatus;
import com.eling.elcms.basedoc.service.IBusinessMessageManager;
import com.eling.elcms.basedoc.service.IPersonalInfoManager;
import com.eling.elcms.core.AppContext;
import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.exception.BusinessException;
import com.eling.elcms.core.service.impl.GenericManagerImpl;
import com.eling.elcms.core.util.PropertyUtils;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.member.dao.IMemberPointDao;
import com.eling.elcms.member.model.Member;
import com.eling.elcms.member.model.Member.DataSource;
import com.eling.elcms.member.model.Member.DeleteFlag;
import com.eling.elcms.member.model.Member.Source;
import com.eling.elcms.member.model.Member.Status;
import com.eling.elcms.member.model.MemberPoint;
import com.eling.elcms.member.service.IMemberManager;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.ordermanager.service.IServicePointManager;
import com.eling.elcms.system.model.CommonUser;
import com.eling.elcms.travel.dao.IApprovalProcessDao;
import com.eling.elcms.travel.dao.ITravelContractDao;
import com.eling.elcms.travel.model.*;
import com.eling.elcms.travel.model.view.*;
import com.eling.elcms.travel.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class TravelContractManagerImpl extends GenericManagerImpl<TravelContract, Long>
		implements ITravelContractManager{

	ITravelContractDao travelContractDao;

	@Autowired
	private ITravelContractChargeManager travelContractChargeManager;
	@Autowired
	private IRoomPersonalInfoManager roomPersonalInfoManager;
	@Autowired
	private IProductRuleDetailManager productDetailManager;
	@Autowired
	private IProductRuleManager productRuleManager;
	@Autowired
	private IMemberManager membermanager;
	@Autowired
	private IPersonalInfoManager personalInfoManager;
	@Autowired
	private ICustomerManager customerManager;
	@Autowired
	private IProductBatchManager batchManager;
	@Autowired
	private IServicePointManager servicepointmanager;
	@Autowired
	private IWelfareConsumptionCouponManager welfareConsumptionCouponManager;
	@Autowired
	private IAllianceSetlDetailManager allSetlDetManager;
	@Autowired
	private ICheckOutSetlDetailManager checkOutSetlDetailManager;
	@Autowired
	IApprovalProcessDao approvalAcitonDao;
	@Autowired
	private IMemberPointDao memberPointDao;
	@Autowired
	private IReturnCredentialsManager returnCredentialsManager;
	@Autowired
	private ICertificatesTransferManager certificatesTransferManager;
	@Autowired
 	private IBusinessMessageManager businessMessageManager;

	@Autowired
	public void setDao(ITravelContractDao dao) {
		this.dao = dao;
		this.travelContractDao = dao;
	}

	@Override
	public TravelContract saveAll(TravelContract travelContract, Boolean isMem, Long pkLong) {
		TravelContract traContract = new TravelContract();
		List<TravelContract> travelList = query(traContract);
		for (TravelContract tra : travelList) {
			if (tra.getContactNo().equals(travelContract.getContactNo()) || tra.getMemberCertificates().equals(
					travelContract.getMemberCertificates() == null ? 0 : travelContract.getMemberCertificates())) {
				if (!tra.getPkTravelContract().equals(travelContract.getPkTravelContract())) {
					throw new BusinessException("合同号或会员证号已存在");
				}
			}
		}
		Member memCond = new Member();
		if (isMem == null ? false : isMem) {// 会员签约
			// 会员不存在时新增
			if (null == pkLong) {
				memCond = memSave(travelContract.getMember(), memCond.getPersonalInfo());
				MemberPoint memberPoint = new MemberPoint();
				memberPoint.setPkMember(memCond.getPkMember());
				memberPoint.setPkServicePoint(travelContract.getServicePoint().getPkServicePoint());
			} else {
				memCond = membermanager.get(pkLong);
			}
		} else {// 意向客户签约
			Customer cusCond = customerManager.get(pkLong);
			memCond = memSave(memCond, cusCond.getPersonalInfo());
			cusCond.setMember(memCond);
			cusCond.setTransMember(true);
			cusCond.setStatus(com.eling.elcms.travel.model.Customer.Status.Contract);
			cusCond = customerManager.save(cusCond);
		}
		if (travelContract.getServicePoint().getPkServicePoint() != null) {
			MemberPoint memberPoint = new MemberPoint();
			memberPoint.setPkServicePoint(travelContract.getServicePoint().getPkServicePoint());
			memberPoint.setPkMember(memCond.getPkMember());
			memberPoint.setVersion(0);
			memberPointDao.save(memberPoint);
		}
		ProductRuleDetail pd = new ProductRuleDetail();
		ProductRule pr = travelContract.getProductRule();
		pd.setProductRule(pr);
		pd.setProductType(travelContract.getProductType());
		pd.setProductBatch(travelContract.getProductBatch());
		List<ProductRule> list = productRuleManager.query(pr);
		ProductRule prs = new ProductRule();
		if (list.size() > 0) {
			prs = list.get(0);
		}
		travelContract.setProductRule(prs);
		travelContract.setStatus(TravelContract.Status.Initial);
		travelContract.setMember(memCond);
		if (null != travelContract.getProductBatch()) {
			ProductBatch pb = batchManager.get(travelContract.getProductBatch().getPkProductBatch());
			travelContract.setProductBatch(pb);
		}
		ServicePoint sp = servicepointmanager.get(travelContract.getServicePoint().getPkServicePoint());
		travelContract.setServicePoint(sp);
		travelContract.setVisitStatus(TravelContract.VisitStatus.NoVisit);
		// 计算余额
		travelContract = SumPrice(travelContract);

		//保存地址
		Set<ContactAddress> contactAddressList = new HashSet<>();
		ContactAddress contactAddress = new ContactAddress();
		contactAddress.setAddress(travelContract.getMember().getPersonalInfo().getAreaAddress());
		contactAddress.setPersonalInfo(travelContract.getMember().getPersonalInfo());
		contactAddress.setDetailAddress(travelContract.getMember().getPersonalInfo().getAddress());
		contactAddress.setAddressStatus(AddressStatus.DefaultAddress);
		contactAddress.setDeleteFlag(false);
		
		contactAddressList.add(contactAddress);
		travelContract.getMember().getPersonalInfo().setContactAddresses(contactAddressList);
		CommonUser user = (CommonUser) AppContext.curUser();
		if (travelContract.getPkTravelContract() == null) {
			travelContract.setOperator(user);
			travelContract = travelContractDao.save(travelContract);
			// 新增推收费单
			TravelContractCharge charge = new TravelContractCharge();
			charge.setTravelContract(travelContract);
			charge.setStatus(TravelContractCharge.PayStatus.NoPay);
			charge.setVersion(0);
			travelContractChargeManager.save(charge);
			businessMessageManager.saveBusinessMessage(new BusinessMessage(TargetType.Role,TaskType.TravelContractCharge,travelContract.getPkTravelContract()));

		} else {

			travelContract = travelContractDao.save(travelContract);
		}
		return travelContract;
	}

	private TravelContract SumPrice(TravelContract travelContract) {
		ProductRuleDetail prd = new ProductRuleDetail();
		//prd.setProductRule(travelContract.getProductRule());
		prd.setProductType(travelContract.getProductType());
		prd.setProductBatch(travelContract.getProductBatch());
		prd.setSeal(false);
		prd = productDetailManager.query(prd).get(0);
		// 余额按天计算
		if (prd.getLiveDays() != null
				&& prd.getUnit().name().equals(com.eling.elcms.travel.model.ProductRuleDetail.Unit.Day.name())) {
			travelContract.setBalTime(Double.valueOf(travelContract.getNumber() * prd.getLiveDays()));
		} else {// 按钱计算
			travelContract.setBalance(travelContract.getNumber() * prd.getPrice());
		}
		return travelContract;
	}

	/**
	 * 保存签约时新增的会员
	 * 
	 * @param member
	 * @return
	 * @author zhoulin
	 */
	private Member memSave(Member member, PersonalInfo per) {// 填充新增时的会员数据
		member.setOrganization(((CommonUser) AppContext.curUser()).getOrganization());
		member.setStatus(Status.Normal);
		member.setSource(Source.Offline);
		member.setDataSource(DataSource.Organization);
		member.setDeleteFlag(DeleteFlag.UnDeleted);
		member.setCreater(((CommonUser) AppContext.curUser()));
		member.setCreateDate(new Date());
		member.setVersion(0);

		if (null != per) { // 客户签约，抽取人员信息
			member.setPersonalInfo(per);
		} else {
			PersonalInfo personalInfo = member.getPersonalInfo();
			PersonalInfo temp = new PersonalInfo();
			if(personalInfo.getIdNumber() != null){
				if(personalInfo.getIdNumber() == ""){
					personalInfo.setIdNumber(null);
				}else {
					temp = roomPersonalInfoManager.queryById(personalInfo.getIdNumber());
				}
			}
			if(temp != null){
				temp.setName(personalInfo.getName());
				temp.setSex(personalInfo.getSex());
				temp.setPhone(personalInfo.getPhone());
				if(personalInfo.getBirthday() != null){
					temp.setBirthday(personalInfo.getBirthday());
				}
				personalInfo = personalInfoManager.save(temp);
			}
			member.setPersonalInfo(personalInfoManager.save(personalInfo));
		}

		return membermanager.save(member);
	}

	@Override
	public List<ProductBatch> queryProductBatch(TravelContract cond) {
		ProductRuleDetail pd = new ProductRuleDetail();
		pd.setProductType(cond.getProductType());
		pd.setProductRule(cond.getProductRule());
		if (cond.getProductBatch() != null) {
			pd.setProductBatch(cond.getProductBatch());
		}
		pd.setSeal(false);
		List<ProductRuleDetail> detailList = productDetailManager.query(pd);
		List<ProductBatch> batchList = new ArrayList<>();
		for (ProductRuleDetail proDetail : detailList) {
			ProductBatch productBatch = proDetail.getProductBatch();
			batchList.add(productBatch);
		}
		return batchList;
	}

	@Override
	public Msg deleteAll(Long pkTravelContract) {
		TravelContractCharge tcc = new TravelContractCharge();
		tcc.setTravelContract(travelContractDao.get(pkTravelContract));
		List<TravelContractCharge> list = travelContractChargeManager.query(tcc);
		if (list.size() > 0) {
			travelContractChargeManager.remove(list);
		}
		travelContractDao.remove(pkTravelContract);
		return new Msg("删除成功");
	}

	@Override
	public SettlementsRule getContractSetlRuleByType(TravelContract contract, RuleType type) {
		ProductRuleDetail cond = new ProductRuleDetail();
		cond.setProductBatch(contract.getProductBatch());
		cond.setProductType(contract.getProductType());
		List<ProductRuleDetail> details = productDetailManager.query(cond);
		if (details != null && details.size() > 0) {
			return productDetailManager.getPdSetlRuleByType(details.get(0), type);
		} else {
			return null;
		}
	}

	@Override
	public List<RuleScope> getContractSetlRuleScopeByType(TravelContract contract, RuleType type) {
		ProductRuleDetail cond = new ProductRuleDetail();
		cond.setProductBatch(contract.getProductBatch());
		cond.setProductType(contract.getProductType());
		List<ProductRuleDetail> details = productDetailManager.query(cond);
		if (details != null && details.size() > 0) {
			return productDetailManager.getPdSetlRuleScopeByType(details.get(0), type);
		} else {
			return null;
		}
	}

	/**
	 * 合同签约搜索会员及客户
	 * 
	 * @param sc
	 * @param tuView
	 * @return
	 * @author zhoulin
	 */
	@Override
	public List<TravelUserView> searchContractUser(SearchCondition sc, TravelUserView tuView) {
		// 搜索会员
		Member memCond = new Member();
		sc.setQueryCondition(memCond);
		List<Member> memList = membermanager.search(sc);
		// 去除已经转让过权证的会员
		List<Long> pkList = new ArrayList<Long>();
		for (Member m : memList) {
			pkList.add(m.getPkMember());
		}
		CertificatesTransfer ct = new CertificatesTransfer();
		PropertyUtils.setProperty(ct, "assignor.pkMemberIn", pkList);
		List<CertificatesTransfer> certificatesTransfers = certificatesTransferManager.query(ct);
		for (CertificatesTransfer c : certificatesTransfers) {
			for (Iterator<Member> iter = memList.iterator(); iter.hasNext();) {
				Member member = (Member) iter.next();
				if (c.getAssignor().getPkMember().equals(member.getPkMember())) {
					iter.remove();
				}
			}
		}

		// 搜索客户
		Customer cusCond = new Customer();
		sc.setQueryCondition(cusCond);
		List<Customer> cusList = customerManager.search(sc);

		List<TravelUserView> returnList = new ArrayList<TravelUserView>();

		for (Member mem : memList) {
			TravelUserView tuView1 = new TravelUserView();
			tuView1.setPkLong(mem.getPkMember());
			tuView1.setPersonalInfo(mem.getPersonalInfo());
			tuView1.setIsMem(true);
			returnList.add(tuView1);
		}

		for (Customer cus : cusList) {
			if (cus.getStatus() != Customer.Status.Contract) {
				TravelUserView tuView2 = new TravelUserView();
				tuView2.setPkLong(cus.getPkCustomer());
				tuView2.setPersonalInfo(cus.getPersonalInfo());
				tuView2.setIsMem(false);
				returnList.add(tuView2);
			}
		}

		return returnList;
	}

	/**
	 * 查询签约客户
	 */
	@Override
	public List<ContractStatView> countValid(Date signUpDate, Date signUpDateEnd) {
		return travelContractDao.conutValid(signUpDate, signUpDateEnd);
	}

	/**
	 * 统计签约客户
	 */
	@Override
	public List<contractGridValid> contractValid(Long pkProduct, Long pkProductType, Date signUpDate,
			Date signUpDateEnd) {
		return travelContractDao.contractValid(pkProduct, pkProductType, signUpDate, signUpDateEnd);
	}

	/**
	 * 查询闲置的会员证件
	 * 
	 * @author xuechao
	 * @throws Exception
	 */
	@Override
	public List<TravelContractView> queryIdle(TravelContractView cond) throws Exception {

		TravelContract tTravelContract = new TravelContract();
		tTravelContract.setMemberCertificates(cond.getTravelContract().getMemberCertificates());
		List<TravelContract> travelContractList = travelContractDao.query(tTravelContract);
		List<TravelContractView> travelContractViews = new ArrayList<TravelContractView>();

		if (travelContractList != null && travelContractList.size() > 0) {
			for (TravelContract tc : travelContractList) {
				TravelContractView tv = new TravelContractView();

				if (tc.getStatus() != TravelContract.Status.Valid) {
					throw new Exception("会员证不是有效状态");
				} else {
					Integer size = travelContractDao.queryOccupied(travelContractList.get(0).getPkTravelContract());
					if (size > 0) {
						throw new Exception("会员证正在使用");
					} else {
						tv.setTravelContract(tc);
						List<WelfareConsumptionCouponStatisticsView> wccdList = welfareConsumptionCouponManager
								.queryStatistics(tc);
						tv.setWelfareStatisticsViews(wccdList);
						travelContractViews.add(tv);
					}
				}
			}
		}
		List<TravelContractView> viewList = new ArrayList<>();
		for (TravelContractView travelContractView : travelContractViews) {
			if (3==(travelContractView.getTravelContract().getProductType().getProduct().getPkProduct())) {
				TravelContract travelContract = travelContractView.getTravelContract();
				ProductRuleDetail prd = new ProductRuleDetail();
				prd.setProductRule(travelContract.getProductRule());
				prd.setProductType(travelContract.getProductType());
				prd.setProductBatch(travelContract.getProductBatch());
				prd.setSeal(false);
				prd = productDetailManager.query(prd).get(0);
				travelContract.setBalance((travelContractView.getTravelContract().getPrice() / prd.getLiveDays())
						* travelContractView.getTravelContract().getBalTime());
				travelContractView.setTravelContract(travelContract);
				viewList.add(travelContractView);
			}
			viewList.add(travelContractView);
		}
		return viewList;
	}

	@Override
	public ReturnCredentialsView queryByCard(TravelContract cond, Long pkReturnCredentials, Boolean flag) {
		ReturnCredentialsView view = new ReturnCredentialsView();
		// 得到合同签约
		TravelContract tc = new TravelContract();
		if (cond.getContactNo() != null) {
			PropertyUtils.setProperty(tc, "contactNo", cond.getContactNo());
		}
		if (cond.getMemberCertificates() != null) {
			PropertyUtils.setProperty(tc, "memberCertificates", cond.getMemberCertificates());
		}
		if (query(tc).size() > 0) {
			tc = query(tc).get(0);
			if (!tc.getProductRule().getIsReturn()) {
				throw new BusinessException("该会员证不支持退证！");
			}
		} else {
			throw new BusinessException("没有该会员证号！");
		}
		if (flag) {
			ReturnCredentials returnCredentials = new ReturnCredentials();
			returnCredentials.setTravelContract(tc);
			List<ReturnCredentials> lists = returnCredentialsManager.query(returnCredentials);
			if (!lists.isEmpty()) {
				throw new BusinessException("该会员证号已经进行退证申请了！");
			}
		}

		// 根据签约查询对应的消费券
		WelfareConsumptionCoupon wcc = new WelfareConsumptionCoupon();
		wcc.setTravelContract(tc);
		List<WelfareConsumptionCoupon> list = welfareConsumptionCouponManager.query(wcc);
		List<WelfareccView> views = new ArrayList<WelfareccView>();
		if (!list.isEmpty()) {
			// 统计消费券子表信息
			List<Long> pklist = new ArrayList<Long>();
			for (WelfareConsumptionCoupon w : list) {
				pklist.add(w.getPkWelfarecc());
			}
			views = welfareConsumptionCouponManager.queryDetail(pklist);
			// 根据签约查询对应的报名
			SignUpRegister signUp = new SignUpRegister();
			signUp.setTravelContract(tc);

			// 查询所有在售的产品定义
			ProductRuleDetail detail = new ProductRuleDetail();
			detail.setSeal(false);
			List<Long> pkList = new ArrayList<Long>();
			if (pkList.size() > 0) {
				// 根据报名去查询入住联盟结算
				AllianceSetlDetail alliance = new AllianceSetlDetail();
				PropertyUtils.setProperty(alliance, "signUpCharge.signUpRegister.pkSignUpRegisterIn", pkList);
				List<AllianceSetlDetail> alliances = allSetlDetManager.query(alliance);
				int j = 0;
				for (AllianceSetlDetail a : alliances) {
					if (!a.getFinish()) {
						j++;
					}
				}
				if (j > 0) {
					throw new BusinessException("该会员证有正在进行中的业务，不能退证");
				}

				// 根据报名去查询组团退房结算
				CheckOutSetlDetail checkOut = new CheckOutSetlDetail();
				PropertyUtils.setProperty(checkOut, "roomPersonalInfo.signUpRegister.pkSignUpRegisterIn", pkList);
				List<CheckOutSetlDetail> checkOuts = checkOutSetlDetailManager.query(checkOut);
				int k = 0;
				for (CheckOutSetlDetail c : checkOuts) {
					if (!c.getRoomPersonalInfo().getCheckOutSettlement().getCheckOutSettlement()) {
						k++;
					}
				}
				if (k > 0) {
					throw new BusinessException("该会员证有正在进行中的业务，不能退证");
				}
			}
			view.setWelfareccList(views);
			view.setBalance(tc.getBalance());
		} else {
			view.setWelfareccList(views);
			view.setBalance(0.0);
		}
		view.setTravelContract(tc);
		
		if (3==(view.getTravelContract().getProductType().getProduct().getPkProduct())) {
			TravelContract travelContract = view.getTravelContract();
			ProductRuleDetail prd = new ProductRuleDetail();
			prd.setProductRule(travelContract.getProductRule());
			prd.setProductType(travelContract.getProductType());
			prd.setProductBatch(travelContract.getProductBatch());
			prd.setSeal(false);
			if(!productDetailManager.query(prd).isEmpty()){
				prd = productDetailManager.query(prd).get(0);
				travelContract.setBalance((view.getTravelContract().getPrice() / prd.getLiveDays())
						* view.getTravelContract().getBalTime());
				view.setBalance((view.getTravelContract().getPrice() / prd.getLiveDays())
						* view.getTravelContract().getBalTime());
			}
			view.setTravelContract(travelContract);
		}
		return view;
	}

	@Override
	public List<Member> pageQueryByPoint(Member cond, Long pkCommunityData, Long pkServicePoint, Long pkInterest,
			String pkOrg, Boolean exitMember) {
		// 获取分页相关条件
		Integer firstResult = PropertyUtils.getProperty(cond, "firstResult");
		Integer maxResults = PropertyUtils.getProperty(cond, "maxResults");
		Boolean queryCount = PropertyUtils.getProperty(cond, "queryCount");
		Integer countResults = 0;
		// 第一次查询需要 查询总数
		Member member = new Member();
		if (queryCount != null && queryCount) {
			countResults = Integer.parseInt(travelContractDao.pageQueryByPoint(cond, pkCommunityData, pkServicePoint,
					pkInterest, firstResult, maxResults, queryCount, pkOrg, exitMember).get(0).toString());
			PropertyUtils.setProperty(member, "pkMemberIn", travelContractDao.pageQueryByPoint(cond, pkCommunityData,
					pkServicePoint, pkInterest, firstResult, maxResults, false, pkOrg, exitMember));
		} else {
			PropertyUtils.setProperty(member, "pkMemberIn", travelContractDao.pageQueryByPoint(cond, pkCommunityData,
					pkServicePoint, pkInterest, firstResult, maxResults, queryCount, pkOrg, exitMember));
		}
		String gridFetchProperties = "pkMember," + "personalInfo.name," + "personalInfo.sex.*,"
				+ "personalInfo.birthday," + "personalInfo.idNumber," + "memberNumber," + "personalInfo.mobilePhone,"
				+ "status.*," + "version," + "interest.name";
		PropertyUtils.setProperty(member, "fetchProperties", gridFetchProperties);
		if (pkOrg != null) {
			PropertyUtils.setProperty(member, "validatePrivilege", false);
		}
		List<Member> list = membermanager.query(member);

		/*
		 * List<Long> queryMemPkList = travelContractDao.queryMemPk();
		 * for(Member m : list){ Long pkMember = m.getPkMember();
		 * if(queryMemPkList.contains(pkMember)){
		 * queryMemPkList.remove(pkMember); } } StringBuffer sb = new
		 * StringBuffer(); String strCond = null; for(Long ll : queryMemPkList){
		 * sb.append(ll); sb.append(","); String string = sb.toString(); strCond
		 * = string.substring(0, string.length()-1); } List<Member> listMember =
		 * travelContractDao.queryMember(strCond); list.addAll(listMember);
		 * countResults = list.size();
		 */
		// 如果是第一次查询 将总数赋值给每条数据的 countResults 属性
		if (queryCount != null && queryCount) {
			for (Member me : list) {
				PropertyUtils.setProperty(me, "countResults", countResults);
			}
		}
		return list;
	}

	@Override
	public List<Member> searchMemPagingWithCard(SearchCondition sc, Member cond, Long pkCommunityData,
			Long pkServicePoint, Long pkInterest, String pkOrg, Boolean exitMember) {
		// 获取分页相关条件
		Integer firstResult = PropertyUtils.getProperty(cond, "firstResult");
		Integer maxResults = PropertyUtils.getProperty(cond, "maxResults");
		Boolean queryCount = PropertyUtils.getProperty(cond, "queryCount");
		Integer countResults = 0;
		// 第一次查询需要 查询总数
		Member member = new Member();
		if (queryCount != null && queryCount) {
			countResults = Integer
					.parseInt(travelContractDao.searchMemPagingWithCard(sc, cond, pkCommunityData, pkServicePoint,
							pkInterest, firstResult, maxResults, queryCount, pkOrg, exitMember).get(0).toString());
			PropertyUtils.setProperty(member, "pkMemberIn", travelContractDao.searchMemPagingWithCard(sc, cond,
					pkCommunityData, pkServicePoint, pkInterest, firstResult, maxResults, false, pkOrg, exitMember));
		} else {
			PropertyUtils.setProperty(member, "pkMemberIn",
					travelContractDao.searchMemPagingWithCard(sc, cond, pkCommunityData, pkServicePoint, pkInterest,
							firstResult, maxResults, queryCount, pkOrg, exitMember));
		}
		String gridFetchProperties = "pkMember," + "personalInfo.name," + "personalInfo.sex.*,"
				+ "personalInfo.birthday," + "personalInfo.idNumber," + "memberNumber," + "personalInfo.mobilePhone,"
				+ "status.*," + "version," + "interest.name";
		PropertyUtils.setProperty(member, "fetchProperties", gridFetchProperties);
		if (pkOrg != null) {
			PropertyUtils.setProperty(member, "validatePrivilege", false);
		}
		List<Member> list = membermanager.query(member);
		// 如果是第一次查询 将总数赋值给每条数据的 countResults 属性
		if (queryCount != null && queryCount) {
			for (Member me : list) {
				PropertyUtils.setProperty(me, "countResults", countResults);
			}
		}
		return list;
		/*
		 * if(sc.getS()!=null && sc.getS().length()==10){ CardManagement card =
		 * new CardManagement(); card.setChipNumber(sc.getS());
		 * List<CardManagement> list = cardManagementManager.query(card);
		 * if(list.size()>0){ sc.setS(list.get(0).getCardNumber()); String[]
		 * search=sc.getSearchProperties(); search=ArrayUtils.add(search,
		 * "memberNumber"); sc.setSearchProperties(search); } } Member mem=new
		 * Member(); PropertyUtils.copyProperties(mem, cond);
		 * PropertyUtils.setProperty(mem, "firstResult",null);
		 * PropertyUtils.setProperty(mem, "maxResults",null);
		 * sc.setQueryCondition(mem); List<Member> list =
		 * membermanager.search(sc); return membermanager.setCountResults(list,
		 * cond);
		 */
	}

	@Override
	public ProductRuleDetail getProductDetail(TravelContract cond) {
		ProductRuleDetail pd = new ProductRuleDetail();
		pd.setProductBatch(cond.getProductBatch());
		pd.setProductType(cond.getProductType());
		if (cond.getProductBatch() != null) {
			pd.setProductBatch(cond.getProductBatch());
		}
		pd.setSeal(false);
		List<ProductRuleDetail> detailList = productDetailManager.query(pd);
		ProductRuleDetail productRuleDetail = detailList.get(0);
		return productRuleDetail;
	}

	@Override
	public TravelContractView searchByMemberCertificates(String memberCertificates) {
		
		return travelContractDao.searchByMemberCertificates(memberCertificates);
	}

}
